package arch.chameleon.plugin.mojo;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * @goal create
 *
 */
public class ProjectBuilderMojo extends AbstractMojo {

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {		
		getLog().info("prototypeArchLocation: " + prototypeArchLocation.getAbsolutePath());
		getLog().info("basedir: " + basedir.getAbsolutePath());
		
		try {
			FileUtils.copyDirectory(prototypeArchLocation, basedir, new FileFilter(){
				@Override
				public boolean accept(File pathname) {
					if(pathname.isDirectory() && (pathname.getName().startsWith(".") || pathname.getName().equals("target"))){
						return false;
					}
					if(pathname.isFile() && pathname.getName().equals("pom.xml")){
						return false;
					}
					return true;
				}
				
			});
			getLog().info("resources copied");
			
			//getLog().info("project name: " + projectName);
			//getLog().info("creating package: com." + projectName);
			
			//boolean bCreated = new File(basedir.getAbsolutePath().concat("/src/main/java/com/").concat(projectName)).mkdirs();
			
			//getLog().info("created package: " + bCreated);
		} catch (IOException e) {
			throw new MojoFailureException(e.getMessage());
		}
		
	}
	
	/**
	 * @parameter
	 * @required
	 */
	private File prototypeArchLocation;
	
	/**
	 * @parameter expression="${project.artifactId}"
	 * @required
	 * @readonly
	 */
	private String projectName;
	
	/**
	 * @parameter expression="${project.basedir}"
	 * @required
	 * @readonly
	 */
	private File basedir;

}
